﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ServicesSheet_PlaneTicket : System.Web.UI.Page
{
    private Srvtools.WebDataSet WMaster;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitializeComponent();
            Master.DataSource = WMaster;


            MasterPage_MasterPage master = (MasterPage_MasterPage)this.Page.Master;
            master.HelpHref = "~/Help/ServicesSheet/机票申请.htm";
            master.PageName = "机票申请";
            master.PicUrl = "";
            master.IntiBar();
        }
    }

    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        this.InitData();
    }

    private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ServicesSheet_PlaneTicket));
        this.WMaster = new Srvtools.WebDataSet();
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).BeginInit();
        // 
        // WMaster
        // 
        this.WMaster.Active = true;
        this.WMaster.AlwaysClose = true;
        this.WMaster.DeleteIncomplete = true;
        this.WMaster.Guid = null;
        this.WMaster.LastKeyValues = null;
        this.WMaster.Locale = new System.Globalization.CultureInfo("zh-CN");
        this.WMaster.PacketRecords = 1;
        this.WMaster.Position = -1;
        this.WMaster.RemoteName = "ServiceSheet.Services_PlaneTicket";
        this.WMaster.ServerModify = true;
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).EndInit();
    }

    protected object GetEmpId()
    {
        String str = Srvtools.CliUtils.GetValue("_UserCode")[1].ToString();
        str = int.Parse(str).ToString();
        return str;
    }

    protected object GetDepartmentName()
    {
        string _EmpId = "";
        Srvtools.WebRefVal _xx = WebFormView1.FindControl("WebRefVal1") as Srvtools.WebRefVal;
        if (_xx != null && !String.IsNullOrEmpty(_xx.BindingValue))
            _EmpId = _xx.BindingValue;
        else
            _EmpId = GetEmpId().ToString();
        DataRow[] _drs = this.WEmp.CommandTable.Select("EmployeeID=" + _EmpId);
        if (_drs.Length > 0)
            return _drs[0]["DepartmentName"];
        return "";
    }

    private void InitData()
    {
        if (this.Request.Params["P"] == "1")
        {
            this.WebFormView2.Visible = false;
            this.WebFormView3.Visible = false;
        }
        else if (this.Request.Params["P"] == "3")
        {
            this.WebFormView2.Visible = true;
            this.WebFormView3.Visible = false;
            this.FLWebNavigator1.NavControls.RemoveAt("Approve");
        }
        else if (this.Request.Params["P"] == "4")
        {
            this.WebFormView2.Visible = true;
            this.WebFormView3.Visible = false;
            Button btn;
            btn = (Button)this.WebFormView2.FindControl("btnEditInquirePrice");
            if (btn != null)
                btn.Visible = false;
            btn = (Button)this.WebFormView2.FindControl("btnSubmitInquirePrice");
            if (btn != null)
                btn.Visible = false;
            btn = (Button)this.WebFormView2.FindControl("btnSaveInquirePrice");
            if (btn != null)
                btn.Visible = false;
            btn = (Button)this.WebFormView2.FindControl("btnCancelInquirePrice");
            if (btn != null)
                btn.Visible = false;
        }
        else if (this.Request.Params["P"] == "5")
        {
            this.WebFormView2.Visible = true;
            this.WebFormView3.Visible = true;
            Button btn;
            btn = (Button)this.WebFormView2.FindControl("btnEditInquirePrice");
            if (btn != null)
                btn.Visible = false;
            btn = (Button)this.WebFormView2.FindControl("btnSubmitInquirePrice");
            if (btn != null)
                btn.Visible = false;
            btn = (Button)this.WebFormView2.FindControl("btnSaveInquirePrice");
            if (btn != null)
                btn.Visible = false;
            btn = (Button)this.WebFormView2.FindControl("btnCancelInquirePrice");
            if (btn != null)
                btn.Visible = false;
            btn = (Button)this.WebFormView3.FindControl("btnEditTicketPrice");
            if (btn != null)
                btn.Visible = false;
            btn = (Button)this.WebFormView3.FindControl("btnSubmitTicketPrice");
            if (btn != null)
                btn.Visible = false;
            btn = (Button)this.WebFormView3.FindControl("btnSaveTicketPrice");
            if (btn != null)
                btn.Visible = false;
            btn = (Button)this.WebFormView3.FindControl("btnCancelTicketPrice");
            if (btn != null)
                btn.Visible = false;
        }
        else if (this.Request.Params["P"] == "6")
        {
            this.WebFormView2.Visible = true;
            this.WebFormView3.Visible = true;
            Button btn;
            btn = (Button)this.WebFormView2.FindControl("btnEditInquirePrice");
            if (btn != null)
                btn.Visible = false;
            btn = (Button)this.WebFormView2.FindControl("btnSubmitInquirePrice");
            if (btn != null)
                btn.Visible = false;
            btn = (Button)this.WebFormView2.FindControl("btnSaveInquirePrice");
            if (btn != null)
                btn.Visible = false;
            btn = (Button)this.WebFormView2.FindControl("btnCancelInquirePrice");
            if (btn != null)
                btn.Visible = false;
            this.FLWebNavigator1.NavControls.RemoveAt("Approve");
        }
        else
        {
            this.WebFormView2.Visible = false;
            this.WebFormView3.Visible = false;
        }
    }

    protected void WebFormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
    {
        e.NewValues["DepartmentName"] = GetDepartmentName().ToString();
        e.OldValues["DepartmentName"] = e.NewValues["DepartmentName"];
    }

    protected void WebFormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        e.Values["DepartmentName"] = GetDepartmentName().ToString();
    }

    protected void WebFormView2_ItemCommand(object sender, FormViewCommandEventArgs e)
    {
        if (e.CommandName == "Save")
        {
            this.WebFormView2.UpdateItem(false);
            Master.ApplyUpdates();
        }
    }

    protected void WebFormView3_ItemCommand(object sender, FormViewCommandEventArgs e)
    {
        if (e.CommandName == "Save")
        {
            this.WebFormView3.UpdateItem(false);
            Master.ApplyUpdates();
        }
    }

    protected void btnSubmitInquirePrice_Click(object sender, EventArgs e)
    {
        FLWebNavigator1.Approve();
    }

    protected void btnSubmitTicketPrice_Click(object sender, EventArgs e)
    {
        FLWebNavigator1.Approve();
    }
   
}
